<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/11/11
 * Time: 15:39
 * Features: 模块授权关系
 */

namespace app\adminapiv3\model;


class HostModuleRelationModel extends BaseModel
{
    /**
     * 根据资产组id查询该组的最小授权数(已授权数)
     * @param int       $groupId   资产组id
     * @param string    $moduleKey 模块标识
    */
    public function getMinAuthNum($groupId,$moduleKey){
       return $this->alias('r')
            ->leftJoin('host h','r.host_id=h.id')
            ->where('h.group_id',$groupId)
            ->where("r.{$moduleKey}",1)
            ->count();
    }

    /**
     * 查询整个模块的已授权主机数
    */
    public function getModuleAuthNum($moduleKey){
        return $this->where("{$moduleKey}",1)->count();
    }

}